package com.ybkj.daijia.server.controller;

import com.ybkj.daijia.page.Page;
import com.ybkj.daijia.page.Pageable;
import com.ybkj.daijia.page.domain.Sort;
import com.ybkj.daijia.server.service.GasOrderService;
import com.ybkj.daijia.server.service.GasStationService;
import java.io.IOException;
import java.text.ParseException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(value = "gaslogin")
public class GasLoginController {

    @Autowired
    private GasStationService gasStationService;

    @Autowired
    private GasOrderService gasOrderService;

    @RequestMapping(value = "login", method = RequestMethod.GET)
    public @ResponseBody
    ModelAndView login() {
        ModelAndView mv = new ModelAndView();
//		mv.setViewName("gaslogin/login");
        return mv;
    }

    @RequestMapping(value = "inLogin", method = RequestMethod.POST)
    public @ResponseBody
    Map<String, Object> inLogin(
        @RequestParam(required = true, value = "username") String username,
        @RequestParam(required = true, value = "password") String password,
        @RequestParam(required = true, value = "captcha") String captcha,
        HttpServletRequest req) {
        Map<String, Object> map = new HashMap<String, Object>();
        return map;
    }

    @RequestMapping(value = "gasList", method = RequestMethod.GET)
    public @ResponseBody
    ModelAndView gasList(HttpServletRequest req) {

        ModelAndView mv = new ModelAndView();
//		Object gasStation = req.getSession().getAttribute("currentGas");
//		if (null == gasStation) {
//			mv.setViewName("gaslogin/login");
//		} else {
//			mv.addObject("gasStation", (GasStation) gasStation);
//			mv.setViewName("gaslogin/orderlist");
//		}

        return mv;
    }

    @RequestMapping(value = "gasLoginOut", method = RequestMethod.GET)
    public @ResponseBody
    ModelAndView gasLoginOut(HttpServletRequest req) {

        ModelAndView mv = new ModelAndView();
//		req.getSession().removeAttribute("currentGas");
//		mv.setViewName("gaslogin/login");
        return mv;
    }

    @RequestMapping(value = "orderListData", method = RequestMethod.GET)
    public @ResponseBody
    Page<Map<String, Object>> orderListData(
        @RequestParam("gsId") Long gsId,
        @RequestParam(required = false, value = "statusSelect") String statusSelect,
        @RequestParam(required = false, value = "params") String params,
        @RequestParam(required = false, value = "startTime") String startTime,
        @RequestParam(required = false, value = "endTime") String endTime,
        @RequestParam(required = false, value = "page") Integer page,
        @RequestParam(required = false, value = "rows") Integer rows)
        throws ParseException {
        Page<Map<String, Object>> mapPage = new Page<Map<String, Object>>() {
            @Override
            public int getTotalPages() {
                return 0;
            }

            @Override
            public long getTotalElements() {
                return 0;
            }

            @Override
            public int getNumber() {
                return 0;
            }

            @Override
            public int getSize() {
                return 0;
            }

            @Override
            public int getNumberOfElements() {
                return 0;
            }

            @Override
            public List<Map<String, Object>> getContent() {
                return null;
            }

            @Override
            public boolean hasContent() {
                return false;
            }

            @Override
            public Sort getSort() {
                return null;
            }

            @Override
            public boolean isFirst() {
                return false;
            }

            @Override
            public boolean isLast() {
                return false;
            }

            @Override
            public boolean hasNext() {
                return false;
            }

            @Override
            public boolean hasPrevious() {
                return false;
            }

            @Override
            public Pageable nextPageable() {
                return null;
            }

            @Override
            public Pageable previousPageable() {
                return null;
            }

            @Override
            public Iterator<Map<String, Object>> iterator() {
                return null;
            }
        };
        return mapPage;
    }

    @RequestMapping(value = "exportOrder", method = RequestMethod.GET)
    public void exportOrder(
        @RequestParam("gsId") Long gsId,
        @RequestParam(required = false, value = "statusSelect") String statusSelect,
        @RequestParam(required = false, value = "params") String params,
        @RequestParam(required = false, value = "startTime") String startTime,
        @RequestParam(required = false, value = "endTime") String endTime,
        HttpServletRequest req, HttpServletResponse response)
        throws ParseException {

    }

    @RequestMapping(value = "updateStauts", method = RequestMethod.GET)
    public @ResponseBody
    Map<String, Object> updateStauts(
        @RequestParam("orderId") Long orderId,
        @RequestParam("status") Integer status) {

//		return gasOrderService.updateStauts(orderId, status);
        Map<String, Object> map = new HashMap<>();
        return map;

    }

    @RequestMapping(value = "queryById", method = RequestMethod.GET)
    public @ResponseBody
    Map<String, Object> queryById(
        @RequestParam("orderId") Long orderId) {

        Map<String, Object> map = new HashMap<String, Object>();

        return map;

    }

    // 备注
    @RequestMapping(value = "remark", method = RequestMethod.POST)
    public @ResponseBody
    Map<String, Object> remark(Long id,
        @RequestParam(required = false, value = "memo") String memo) {
//		return gasOrderService.remark(id, memo);
        Map<String, Object> map = new HashMap<>();
        return map;
    }


    @RequestMapping(value = "paymentsRecordExport/{id}", method = RequestMethod.GET)
    public void paymentsExport(
        @PathVariable("id") Long gsid,
        @RequestParam(required = false, value = "startTime") String startTime,
        @RequestParam(required = false, value = "endTime") String endTime,
        HttpServletRequest req, HttpServletResponse response)
        throws IOException {

    }

    /*
     * 资金流水
     */
    @RequestMapping(value = "paymentsRecord/{id}", method = RequestMethod.GET)
    public ModelAndView paymentsRecord(
        @PathVariable("id") Long gsid,
        @RequestParam(required = false, value = "startTime") String startTime,
        @RequestParam(required = false, value = "endTime") String endTime,
        HttpServletRequest req) {

        ModelAndView mv = new ModelAndView();

        return mv;
    }


}
